package com.firmail.exception.type.cloud;

import com.firmail.enumeration.MockParamsEnum;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;


@Getter
@Slf4j
public enum CloudExceptionType implements MockParamsEnum {
    CLOUD_SYSTEM_EXCEPTION(Constants.EC_INTERNAL_ERROR_CDDE, Constants.EC_INTERNAL_ERROR_DESC),
    CLOUD_PARAMS_ERROR_EXCEPTION(Constants.PARAM_ERROR_CODE, Constants.PARAM_ERROR_CODE_DESC),
    CLOUD_PARAMS_INVALID_EXCEPTION(Constants.PARAM_INVALID_CODE, Constants.PARAM_INVALID_CODE_DESC),
    CLOUD_NO_PERMISSION_EXCEPTION(Constants.NO_PERMISSION_CODE, Constants.NO_PERMISSION_CODE_DESC);

    private Integer code;

    private String message;

    CloudExceptionType(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    /**
     * 根据code获取名字
     */
    public static String getName(Integer code) {

        for (CloudExceptionType et : CloudExceptionType.values()) {
            if (code == et.getCode())
                return et.message;
        }
        return null;
    }

    /**
     * 根据value返回枚举类型,主要在switch中使用
     */
    public static CloudExceptionType getByCode(Integer code) {
        for (CloudExceptionType et : CloudExceptionType.values()) {
            if (code == et.getCode())
                return et;
        }
        return null;
    }


    @Override
    public void print() {
        log.info("{} :{}", this.code, this.message);
    }

    @Override
    public String getInfo() {
        return getMessage();
    }

    class Constants {
        /**
         * 系统错误
         */
        private static final int EC_INTERNAL_ERROR_CDDE = 100000;
        private static final String EC_INTERNAL_ERROR_DESC = "[系统错误.]";
        /**
         * 没有权限
         */
        private static final int NO_PERMISSION_CODE = 100001;
        private static final String NO_PERMISSION_CODE_DESC = "[没有权限.]";
        /**
         * 参数错误
         */
        private static final int PARAM_ERROR_CODE = 100002;
        private static final String PARAM_ERROR_CODE_DESC = "[参数错误.]";
        /**
         * 参数无效
         */
        private static final int PARAM_INVALID_CODE = 100003;
        private static final String PARAM_INVALID_CODE_DESC = "[参数无效.]";
    }
}
